home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / program / wdj0696.zip / HAZZAH.ZIP / TRAPLIST.ASM next >
Assembly Source File  |  1996-03-02  |  8KB  |  319 lines

  1. ;****************************************************************************
  2. ;                                                                           *
  3. ; THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY     *
  4. ; KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE       *
  5. ; IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR     *
  6. ; PURPOSE.                                                                  *
  7. ;                                                                           *
  8. ; Copyright (C) 1993-95  Microsoft Corporation.  All Rights Reserved.       *
  9. ;                                                                           *
  10. ;****************************************************************************
  11.  
  12. PAGE 58,132
  13. ;******************************************************************************
  14. TITLE TRAPLIST 
  15. ;******************************************************************************
  16. ;
  17. ;   Title:      TRAPLIST.ASM 
  18. ;
  19. ;   Version:    3.00
  20. ;
  21. ;==============================================================================
  22.  
  23.         .386p
  24.  
  25. ;******************************************************************************
  26. ;                             I N C L U D E S
  27. ;******************************************************************************
  28.  
  29.         .XLIST
  30.         INCLUDE VMM.Inc
  31.         INCLUDE Debug.Inc
  32.         INCLUDE IFSMGR.Inc
  33.         INCLUDE TRAPLIST.Inc
  34.         .LIST
  35.  
  36. R0_OPENCREATFILE        equ    0D500h    ; Open/Create a file
  37. R0_WRITEFILE            equ    0D601h    ; Write to a file, no context
  38. R0_CLOSEFILE            equ    0D700h    ; Close a file
  39.  
  40. ;******************************************************************************
  41. ;                V I R T U A L   D E V I C E   D E C L A R A T I O N
  42. ;******************************************************************************
  43.  
  44. Declare_Virtual_Device TRAPLIST, 3, 0, TRAPLIST_Control, TRAPLIST_Dev_ID, VMM_INIT_ORDER+1
  45.                                     
  46. ;******************************************************************************
  47. ;                         L O C A L   D A T A
  48. ;******************************************************************************
  49.  
  50. VxD_LOCKED_DATA_SEG
  51.         ALIGN   4
  52.  
  53. TRAPS_SUPPORTED EQU  400
  54.  
  55. pPrevHook dd 0
  56. numTraps dw 0
  57. VxDNameBuf db 80 dup (0)
  58. FileName  db "vxdtraps.lst", 0
  59. FileHandle dd 0
  60. FilePos    dd 0
  61. IFDEF WIN31
  62. V86Address
  63. ENDIF
  64. TrapStruc STRUCT
  65. Port dd 0
  66. VxDAddr dd 0
  67. TrapStruc ENDS
  68.  
  69. TrapTable db (SIZE TrapStruc * TRAPS_SUPPORTED) dup (0)
  70.  
  71. HexTable db 30h, 31h, 32h, 33h, 34h, 35h, 36h, 37h, 38h, 39h
  72.          db 41h, 42h, 43h, 44h, 45h, 46h
  73.          
  74. VxD_LOCKED_DATA_ENDS
  75.  
  76.  
  77. VxD_ICODE_SEG
  78.  
  79. ;******************************************************************************
  80. ;
  81. ;   TRAPLIST_Sys_Crit_Init
  82. ;
  83. ;   DESCRIPTION:
  84. ;       This routine gets some "VM BLOCK" memory.
  85. ;   
  86. ;
  87. ;==============================================================================
  88.  
  89. BeginProc TRAPLIST_Sys_Crit_Init
  90.  
  91.         GetVxDServiceOrdinal eax, Install_IO_Handler ; hook this service
  92.         mov     esi, OFFSET32 TRAPLIST_HookProc     ; with this little front end
  93.         VMMCall Hook_Device_Service         ; grab it
  94.         jc      SHORT not_hooked            ; huh?
  95.         mov     [pPrevHook], esi
  96.   
  97. not_hooked:
  98.         clc
  99.         ret
  100.  
  101. EndProc TRAPLIST_Sys_Crit_Init
  102.  
  103. BeginProc ShortToAscii
  104.  
  105.     ;AX=short integer, SI=locaion for ascii string (must be 4 bytes)
  106.     ;uses BX
  107.     lea ebx, HexTable
  108.     push ax
  109.     and ax, 000Fh
  110.     xlat
  111.     mov BYTE PTR [esi+3], al
  112.     pop ax
  113.     shr ax, 4
  114.     push ax
  115.     and ax, 000Fh
  116.     xlat
  117.     mov BYTE PTR [esi+2], al
  118.     pop ax
  119.     shr ax, 4
  120.     push ax
  121.     and ax, 000Fh
  122.     xlat
  123.     mov BYTE PTR [esi+1], al
  124.     pop ax
  125.     shr ax, 4
  126.     push ax
  127.     and ax, 000Fh
  128.     xlat
  129.     mov BYTE PTR [esi+0], al
  130.     pop ax
  131.     ret
  132.           
  133. EndProc ShortToAscii
  134.  
  135. VxD_ICODE_ENDS
  136.  
  137.  
  138. ;******************************************************************************
  139.  
  140.  
  141. VxD_LOCKED_CODE_SEG
  142.  
  143. ;******************************************************************************
  144. ;
  145. ;   TRAPLIST_Control
  146. ;
  147. ;   DESCRIPTION:
  148. ;
  149. ;       This is a call-back routine to handle the messages that are sent
  150. ;       to VxD's to control system operation. 
  151. ;
  152. ;
  153. ;==============================================================================
  154.  
  155. BeginProc TRAPLIST_Control
  156.  
  157.         Control_Dispatch Sys_Critical_Init, TRAPLIST_Sys_Crit_Init
  158.         Control_Dispatch Init_Complete, TRAPLIST_Init_Complete
  159.         Control_Dispatch System_Exit, TRAPLIST_System_Exit
  160.         clc
  161.         ret
  162.  
  163. EndProc TRAPLIST_Control
  164.  
  165. BeginProc TRAPLIST_Init_Complete
  166.  
  167. IFNDEF WIN3X
  168.     mov esi, OFFSET32 FileName
  169. ELSE        
  170.     VMMcall _Allocate_Temp_V86_Data_Area, 13, 0>
  171.     or      eax, eax        ; zero if error
  172.     jz      error
  173.     mov     [V86Address], eax  ; address of temporary block
  174. ENDIF
  175.     call    FileCreate
  176.     mov     FileHandle, eax
  177.     
  178.     movzx   ecx, numTraps
  179.     dec     ecx
  180.     
  181. getname:    
  182.     push ecx
  183.     mov esi, DWORD PTR TrapTable[ecx*8+4]
  184.     mov ebx, OFFSET32 VxDNameBuf
  185.     VMMCall _GetVxDName, <esi, ebx>
  186.     pop ecx
  187.     mov esi, OFFSET32 VxDNameBuf+10
  188.     mov eax, DWORD PTR TrapTable[ecx*8+0]  
  189.     call ShortToAscii
  190.     mov BYTE PTR [esi+4], 0Dh
  191.     mov BYTE PTR [esi+5], 0Ah
  192.     
  193.     mov     ebx, FileHandle
  194.     mov     edx, FilePos
  195.     mov     esi, OFFSET32 VxDNameBuf
  196.     push    ecx
  197.     mov     ecx, 16
  198.     call    FileWrite
  199.     add     FilePos, 16
  200.             
  201.     pop ecx
  202.     dec ecx
  203.     jnz getname
  204. ;    loop getname
  205.     
  206.     mov ebx, FileHandle
  207.     call FileClose
  208.     
  209.     clc
  210.     ret
  211.     
  212. EndProc TRAPLIST_Init_Complete
  213.  
  214.     ;ESI->name, returns handle in EAX
  215. BeginProc FileCreate
  216. IFNDEF WIN3X
  217.     mov eax, R0_OPENCREATFILE
  218.     mov bx, 2011h   ; write access, deny r/w, no int 24
  219.     mov dx, 12h     ; always create
  220.     xor cx, cx      ; regular file
  221.     call FileCommon
  222.     ret
  223. ELSE    
  224.     mov     [ebp.Client_DS], offset FileName 
  225.     mov     [ebp.Client_DX], offset FileName 
  226.     mov     [ebp.Client_CX], 0011h  ;write access, deny r/w
  227.     mov     [ebp.Client_AX], 003Ch  ;Create File with Handle
  228.     call FileCommon
  229.     ret
  230. ENDIF    
  231. EndProc FileCreate
  232.  
  233.     ;EBX=handle
  234. BeginProc FileClose
  235. IFNDEF WIN3X
  236.     mov eax, R0_CLOSEFILE
  237.     call FileCommon
  238.     ret
  239. ELSE    
  240.     mov     ah, 3Eh              ;Close File with Handle
  241.     call FileCommon
  242.     ret
  243. ENDIF    
  244. EndProc FileClose
  245.     
  246.     ;EBX=handle, EDX=file pos, ESI->buffer, ECX=len
  247. BeginProc FileWrite
  248. IFNDEF WIN3X
  249.     mov eax, R0_WRITEFILE
  250.     call FileCommon
  251.     ret
  252. ELSE    
  253.     mov     dx, seg Buffer
  254.     mov     ds, dx
  255.     mov     dx, offset Buffer   ;ds:dx points to buffer containing data
  256.     mov     ah, 40h             ;Write File or Device
  257.     call FileCommon
  258.     ret
  259. ENDIF    
  260. EndProc FileWrite
  261.  
  262. BeginProc FileCommon
  263. IFNDEF WIN3X    
  264.     VxDCall IFSMgr_Ring0_FileIO
  265.     jc err
  266. err:
  267.     ret
  268. ELSE
  269.     Push_Client_State             ; Save all registers
  270.     VMMcall Begin_Nest_V86_Exec       ; Enter nested execution in V86-mode
  271.     mov     [ebp.Client_AH], 30h  ; 30h = get MS-DOS version #
  272.     mov     eax, 21h                  ; Execute an Int 21h in the
  273.     VMMcall Exec_Int                  ; current VM to call MS-DOS
  274.     mov     ax, [ebp.Client_AX]   ; Load MS-DOS version into AX register
  275.     VMMcall End_Nest_Exec         ; end of nested exec calls
  276.     Pop_Client_State              ; Restore all registers when done
  277.     ret
  278. ENDIF    
  279. EndProc FileCommon    
  280.  
  281. BeginProc TRAPLIST_System_Exit
  282.  
  283.     ; Remove the hook
  284.     mov      esi, offset32 TRAPLIST_HookProc
  285.     GetVxDServiceOrdinal eax, Install_IO_Handler
  286.     VMMCall  Unhook_Device_Service
  287. ;    jc       Error
  288.     ret
  289.     
  290. EndProc TRAPLIST_System_Exit  
  291.  
  292.  
  293. BeginProc TRAPLIST_HookProc, HOOK_PROC, pPrevHook, LOCKED
  294.  
  295.     pushfd                  ; Remember, hooks must preserve all regs
  296.     pushad                  ;
  297.     movzx ecx, numTraps
  298.     cmp ecx, TRAPS_SUPPORTED
  299.     ja outahere
  300.     mov DWORD PTR